/**
 * @param {number[]} nums
 * @param {number} target
 * @return {number[]}
 */
//暴力解法
var twoSum = function(nums, target) {
    for (let i = 0; i< nums.length; i++) {
        for (let j = i + 1; j < nums.length; j++) {
            if (nums[j] == target - nums[i]) {
                return [i,j]
            }
        }
    }
};
// 哈希解法
var twoSum = function(nums, target) {
    let map = new Map()
    for (let i = 0; i < nums.length; i++) {
        if (map.has(target - nums[i])) {
            return [map.get(target- nums[i]) , i]
        }
        map.set( nums[i] , i)
    }
    // return map

}
let nums = [2,7,11,15]
let target = 9;
console.log(twoSum(nums, target))